package com.cmcc.pcap.packet.capture;


import com.cmcc.pcap.packet.sctp.SctpProtocolHandler;
import com.cmcc.pcap.packet.sctp.ngaps.NgapHandler;
import com.cmcc.pcap.packet.sctp.sctp.SctpHandler;
import com.cmcc.pcap.packet.tcp.TcpProtocolHandler;
import com.cmcc.pcap.packet.tcp.http.HttpHandler;
import com.cmcc.pcap.packet.tcp.https.HttpsHandler;
import com.cmcc.pcap.packet.tcp.tcp.TcpHandler;
import com.cmcc.pcap.packet.udp.UdpHandler;
import com.cmcc.pcap.packet.udp.UdpProtocolHandler;
import com.cmcc.pcap.packet.udp.pfcp.PfcpHandler;
import com.cmcc.pcap.packet.udp.quic.QuicHandler;

/**
 * @Auther: zdw
 * @Date: 2019-10-14 10:46
 * @Description:
 */
public class HandlerManager {
    //传入的handler参数
    public static TcpProtocolHandler tcpHandler;
    public static TcpProtocolHandler httpHandler;
    public static TcpProtocolHandler httpsHandler;
    public static UdpProtocolHandler udpHandler;
    public static UdpProtocolHandler quicHandler;
    public static UdpProtocolHandler pfcpHandler;
    public static SctpProtocolHandler sctpHandler;
    public static SctpProtocolHandler ngapHandler;

    /**
     * 获取handler的方法
     *
     * @param type
     * @return
     * @throws IllegalAccessException
     * @throws InstantiationException
     */
    public static synchronized TcpProtocolHandler getHandler(String type) throws IllegalAccessException, InstantiationException {
        if("tcp".equals(type))
        {
        	if(tcpHandler==null)
        		tcpHandler = new TcpHandler();
        	return tcpHandler;
        }
        
        if("http".equals(type))
        {
        	if(httpHandler==null)
        		httpHandler = new HttpHandler();
        	return httpHandler;
        }
        
        if("https".equals(type))
        {
        	if(httpsHandler==null)
        		httpsHandler = new HttpsHandler();
        	return httpsHandler;
        }
        return null;
    }

    public static synchronized UdpProtocolHandler getUdpHandler(String type) throws IllegalAccessException, InstantiationException {
        if("udp".equals(type))
        {
            if (udpHandler == null)
            {
                udpHandler = new UdpHandler();
            }
            return udpHandler;
        }

        if("quic".equals(type))
        {
            if (quicHandler == null)
            {
                quicHandler = new QuicHandler();
            }
            return quicHandler;
        }

        if("pfcp".equals(type))
        {
            if (pfcpHandler == null)
            {
                pfcpHandler = new PfcpHandler();
            }
            return pfcpHandler;
        }

        return null;

    }


    public static synchronized SctpProtocolHandler getSctpHandler(String type) throws IllegalAccessException, InstantiationException {
        if("sctp".equals(type))
        {
            if (sctpHandler == null)
            {
                sctpHandler = new SctpHandler();
            }
            return sctpHandler;
        }

        if ("ngap".equals(type))
        {
            if (ngapHandler == null)
            {
                ngapHandler = new NgapHandler();
            }
            return ngapHandler;
        }

        return null;

    }

}
